<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>在线咨询</title>
<link rel="stylesheet" href="layim/css/layui.css">
</head>
<body>
</body>
<script src="layim/layui.js"></script>
<script>

	var url = "ws://localhost:8080/witmed/chat/100000?0";
	var webSocket = new WebSocket(url);
	
	layui.use('layim', function(layim) {
		
		var layim = layui.layim;
		layim.config({
			init : {
				notice: false,
				mine : {
					"username" : "咨询客户",
					"id" : "100000",
					"status" : "online",
					"remark" : "",
					"avatar" : "static/images/visitor.jpg"
				}
			},
			brief : true
		});
		
		layim.chat({
			name : '在线客服',
			type : 'kefu',
			avatar : 'static/images/brief.gif',
			id : '100001'
		});
		
		layim.setChatMin();

		webSocket.onopen = function(res) {
			console.log(res)
		};

		webSocket.onmessage = function (res) {
			var data = JSON.parse(res.data);
			console.log(data);
			layim.getMessage(data);
		};

		webSocket.onclose = function() {
			webSocket.close();
		};
		
		webSocket.onerror = function() {

		};

		layim.on('sendMessage', function(res) {
			var msg = {
					id : res.to.id,
					msg: res.mine.content
			};
			webSocket.send(JSON.stringify(msg));
		});
	});
	
</script>
</html>














